﻿using CP.Utility;
using GPM;
using LF3.Controllers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LF3.Controllers;
using LF3.Moduls;

namespace LF3Proj
{
    public partial class FrmWireConfig : Form
    {
        public FrmWireConfig()
        {
            InitializeComponent();
        }

        private void FrmWireConfig_Load(object sender, EventArgs e)
        {
            Lf_Material_ConsumeController mc = new Lf_Material_ConsumeController();
            this.lupMatName.Properties.DataSource = mc.GetWireInfo();
            this.gcWire.DataSource = mc.GetWires();
        }

        private void btnSet_Click(object sender, EventArgs e)
        {
            if (this.cmbPipeNo.EditValue == null)
            {
                ExMessageBox.Show("提示信息：管道号不能为空！", AppSetter.SoftName);
                return;
            }
            if (this.lupMatName.EditValue == null)
            {
                ExMessageBox.Show("提示信息：物料名称不能为空！", AppSetter.SoftName);
                return;
            }

            if (ExMessageBox.Confirm("确定要设定喂丝吗？", AppSetter.SoftName) != DialogResult.Yes)
                return;
            try
            {
                Lf_Material_ConsumeController ctl = new Lf_Material_ConsumeController();
                Lf_Set_Wire wire = new Lf_Set_Wire();
                wire.pipe_no = this.cmbPipeNo.EditValue.ToString();
                wire.mat_id = this.lupMatName.EditValue.ToString();
                wire.mat_name = this.lupMatName.Text;
                ctl.SetPipeWire(wire);
                ExMessageBox.Show("提示信息：设定成功！", AppSetter.SoftName);
                LogHelper.Log("设定喂丝画面", "新增", "设定喂丝", wire.pipe_no,wire.mat_id);
                this.gcWire.DataSource = ctl.GetWires();
            }
            catch (Exception ex)
            {
                ExMessageBox.Show(ex.Message, AppSetter.SoftName);
            }

        }

        private void gvWire_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            Lf_Set_Wire wire = this.gvWire.GetRow(e.FocusedRowHandle) as Lf_Set_Wire;
            if (wire == null)
                return;
            this.cmbPipeNo.EditValue = wire.pipe_no;
            this.lupMatName.EditValue = wire.mat_id;
        }
    }
}
